<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="app" uri="http://www.wanrenhui.com" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	  <%@include file="/res/include/base-head.jsp"%>
	  <%@include file="/res/include/jquery-easyui.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/homemaking/homemakingPubitem.js"></script>
  </head>
  <body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false,split:false">
	    	<form id="query-form" class="search_form clearfix">
	            <dl>
					<dt>名称：</dt>
					<dd>
						<input name="name" id="name" type="text" class="txt" maxlength="16"/>
					</dd>
				</dl>
            	<dl>
	                <dt>一级类别：</dt>
	                <dd>
	                	<select id="firstTypeId" onchange="getSecondType(this.value)" class="txt grid-10">
	                		<option value="">--请选择--</option>
	                		<c:forEach var="typeVo" items="${parentList}">
	                			<option value="${typeVo.id }">${typeVo.name }</option>
	                		</c:forEach>
	                	</select>
	                </dd>
	            </dl>
	            <dl>
	                <dt>二级类别：</dt>
	                <dd>
	                	<select id="secondTypeId" name="typeId" class="txt grid-10">
	                		<option value="">--请选择--</option>
	                	</select>
	                </dd>
	            </dl>
	            <p class="search_form_btn">
	            	<input type="button" value="搜索" class="icon_serach" onclick="admin.homemakingPubitem.query()" />
	            </p>
	        </form>
	  	</div>
	    <div data-options="region:'center',border:false">
		    <table id="datagrid" data-options="url:'${pageContext.request.contextPath}/homemaking/pubitem/list',toolbar:'#toolbar'">
				<thead>
					<tr>
						<th data-options="field:'name',width:200,align:'center'">名称</th>
						<th data-options="field:'unit',width:100,align:'center' ">单位</th>
						<th data-options="field:'typeName',width:150,align:'center' ">类别</th>
						<th data-options="field:'status',width:80,align:'center',formatter:formatStatus">状态</th>
						<th data-options="field:'quantity',width:80,align:'center' ">数量</th>
						<th data-options="field:'price',width:80,align:'center' ">价格</th>
			            <th data-options="field:'id',align:'center',width:150,formatter:formatOperation">操作</th>
					</tr>
				</thead>
			</table>
	  	</div>
	</div>

	<script>
		function formatStatus(value,row,index) {
			var l_html = '有效';
			if (value==2) {
				l_html = '失效';
			}
			return l_html;
		}
		function formatOperation(value,row,index) {
			var l_html = '';
			l_html += '<a href="javascript:;" class="table_link" onclick="admin.homemakingPubitem.edit('+row.id+')">编辑</a>';
			return l_html;
		}
		function getSecondType(firstTypeId) {
			if (firstTypeId == "") {
				$("#secondTypeId").html('<option value="">--请选择--</option>');
			} else {
				var data = {parentId:firstTypeId}
				$.post(contextPath+'/homemaking/type/findChildren',data,function(result) {
					if(result.code==1) {
						if (result.map.childrenList) {
							var childrenList = result.map.childrenList;
							var html = [];
							for (var i = 0; i < childrenList.length; i++) {
								html.push('<option value="'+childrenList[i].id+'">'+childrenList[i].name+'</option>');
							}
							$("#secondTypeId").html(html.join(""));
						}
					} else {
						$("#secondTypeId").html('<option value="">--请选择--</option>');
					}
				});
			}
		}
	</script>
  </body>
</html>
